<script language="javascript" src="./include/js/validate.js"></script>
<link rel="stylesheet" href="include/js/xheditor.css" type="text/css" media="screen" />
<link href="images/upcommon/uploadify.css" rel="stylesheet" type="text/css" />
<script language="javascript" src="include/js/jquery.js?v=1.3.2"></script>
<script language="javascript" charset="utf-8" src="include/js/xheditor.js"></script>
<script type="text/javascript" src="include/js/swfobject.js"></script>
<script type="text/javascript" src="include/js/jquery.uploadify.v2.1.0.min.js"></script>
<script type="text/javascript">
$(pageInit);
var editor;
function pageInit()
{
	editor = $('#content').xheditor(true,{height:500,showBlocktag:true,forcePtag:true,clearScript:true,clearStyle:true})[0].xheditor;
}

$(document).ready(function() {
	$("#uploadify").uploadify({
		'uploader'       : 'images/upcommon/uploadify.swf',
		'method'         : 'GET',
		'script'         : './admincp.php',
		'cancelImg'      : 'images/upcommon/cancel.png',
		'folder'         : 'attachments',
		'queueID'        : 'attachlist',
		'fileDesc'       : '请选择gif jpg jpeg png rar zip swf文件',
		'fileExt'        : '*.gif;*.jpg;*.jpeg;*.png;*.rar;*.zip;*.swf',
		'sizeLimit'      : '2048000',
		'auto'           : false,
		'multi'          : true,
		'scriptData'     : {'action':'content','op':'upload','<?=$cookiepre.'sdadmin'?>':'<?=str_replace('+','@',$_COOKIE[$cookiepre.'sdadmin'])?>'},
		onComplete       : function(event, queueID, fileObj,response) {
  							$('#fileQueue').append(response);  
		}
	});
	$.ajax({
		type: "POST",
		url: "admincp.php",
		data: "action=content&op=getunuseattach",
		success: function(msg){
			if(msg){
				var q=confirm('您有未使用的附件，现在是否使用？');
				if(q==true){
					$('#fileQueue').append(msg);
				}
			}
		}
	});
	<? if($fid != 0) {?>
	getsubcate(<?=$fid?>,<?=$content[cateid]?>);
	<? }?>
	
	if(<?=$content[cateid]?> == 4 && <?=$content[special]?> == 1)
	{
		$('#headext').show();
		$('#banner').show();
		$('#template').show();
	}
});
function getsubcate(cid,subcateid)
{
	$.ajax({
			type: "POST",
			url: "admincp.php",
			data: "action=content&op=getsubcate&cid="+cid+"&subcateid="+subcateid,
			success: function(msg){
				if(msg == '') {
					$('#subcate').html('');
					$('#subcate').hide();
				} else {
					$('#subcate').html(msg);
					$('#subcate').show();	
				}
			}
		});
}


function insertsid(sid)
{
	$(function() {
		$('#shopid').val(sid);
	})
}

function changeurl()
{
	if($('#islink').attr('checked')==true)
	{
		$('#url').attr('disabled','');
	}
	else
	{
		$('#url').attr('value','');
		$('#url').attr('disabled','disabled');
	}
}

function ShowDiv(lord_id)
{
	document.getElementById(lord_id).style.display = "block";
}
function CloseDiv(lord_id)
{
	document.getElementById(lord_id).style.display = "none";
}

function delattach(aid) {
	var uu=confirm('确定删除吗！');
	if(uu==false){
		return false;
	}
	$.ajax({
			type: "POST",
			url: "admincp.php?action=content&op=delattach&aid="+aid,
			data: "type=delattach&aid="+aid,
			success: function(msg){
				if(msg == 'ok')
				{
					$('#a_'+aid).remove();
					alert("删除成功");
					return false;
				}
				else
				{
					alert("删除失败");
					return false;
				}
			}
	});
}

function textareasize(obj) {
	if(obj.scrollHeight > 70) {
		obj.style.height = obj.scrollHeight + 'px';
	}
}
</script>
<script language="javascript" src="./include/js/upload.js"></script>
	<div id="nav">
		当前位置: <a href="?action=default">管理首页</a> <span>&gt;</span> 编辑内容
	</div>
	<form id="theform" action="?action=content&op=editsave" method="post" class="block" enctype="multipart/form-data" onSubmit="return Validator.Validate(this,2);">
	<input name="d[contentid]" type="hidden" value="<?=$content['contentid']?>" />
	<table summary="" cellpadding="0" cellspacing="0" border="0" width="100%">
		<tr>
		<th style="padding-bottom: 5px; font-size: 12px; font-weight: bold;"><em>*为必填项</em></th>
		<td>&nbsp;</td>
		</tr>
		<tr>
		<th style="width: 7em;"><em>长标题 *</em></th>
		<td><input name="d[title]" type="text" id="title" size="60" maxlength="80" dataType='Require' msg='请填写长标题' value="<?=$content['title']?>" /><div id="titletips" class="tips">文章标题不超过40个汉字</div></td>
		</tr>
		
		<tr>
		<th><em>短标题 *</em></th>
		<td><input name="d[stitle]" type="text" id="stitle" size="40" maxlength="15" dataType='Require' msg='请填写短标题' value="<?=$content['stitle']?>" /><div id="stitletips" class="tips">文章短标题，10个汉字以内</div></td>
		</tr>
        
		<tr>
		<th><em>分类 *<em></th>
		<td><select name="d[cid]" size="1" onchange="getsubcate(this.value);" dataType='Require' msg='请选择分类'>
			<option value="">---请选择---</option>
 <?php if(is_array($cate)) foreach($cate as $key => $c) { ?>
  <option value="<?php echo $c['cid'];?>" <?php if($content[cateid] == $c[cid]) { ?>selected="selected"<?php } ?>><?php echo $c['cname'];?></option>
  	<!--<?php if($c[subcate]) { ?>
<?php if(is_array($c[subcate])) foreach($c[subcate] as $key => $cs) { ?>
<option value="<?php echo $cs['cid'];?>" <?php if($content[cateid] == $cs[cid]) { ?>selected="selected"<?php } ?>>├ <?php echo $cs['cname'];?></option>
<?php } ?>
<?php } ?>-->
  <?php } ?>
		</select></td>
		</tr>
		
		<tr>
		<th>来源</th>
		<td><input name="d[origin]" type="text" id="origin" size="10" maxlength="15" value="<?=$content['origin']?>" /><div id="origintips" class="tips">文章来源，10个汉字以内</div></td>
		</tr>
		
		<tr>
		<th>作者</th>
		<td><input name="d[author]" type="text" id="author" size="10" maxlength="10" value="<?=$content['author']?>" /><div id="authortips" class="tips">文章作者，6个汉字以内</div></td>
		</tr>
		
		<tr>
		<th>摘要</th>
		<td><textarea id="description" name="d[description]" rows="5" cols="80"><?=$content['description']?></textarea><div id="descriptiontips" class="tips">留空则由程序自动截取内容栏的前25字作为摘要</div></td>
		</tr>
		
		<tr>
		<th>内容</th>
		<td><textarea id="content" name="d[content]" rows="12" cols="80" style="width: 90%"><?=$content['content']?></textarea></td>
		</tr>
		
		<tr>
		<th>附件</th>
		<td>
			<table width="100%" border="0" align="left" cellpadding="0" cellspacing="0">
				<tbody id="image">
					<tr id='tr0'>
						<td height="20" id='td0'>
						<table id="fileQueue">
				<? foreach($attach as $att){?>
					<tr id='a_<?=$att['aid']?>'><td height="20">
						<a href='javascript:void(0);' onclick='delattach(<?=$att['aid']?>);'>[删除]</a>　<a href='javascript:void(0)' id='atta_<?=$att['aid']?>' onmouseover='ShowDiv(<?=$att['aid']?>)' onmouseout='CloseDiv(<?=$att['aid']?>)'><?=$att['filename']?></a>　<a href='javascript:void(0);' onclick="Insertpic1('<?
if(in_array($att['filetype'], array('jpg','gif','png','jpeg','bmp'))){
				echo "<img src={$siteurl}attachments{$att['filepath']}>";
			}elseif(in_array($att['filetype'], array('rar','zip'))){
				echo "<a href={$siteurl}attachments{$att['filepath']}><img src=/images/attachicons/rar.gif></a>";
			}elseif($att['filetype']=='swf'){
				echo "<embed height=400 type=application/x-shockwave-flash width=480 src={$siteurl}attachments{$att['filepath']} loop=true play=true menu=false bgcolor=#ffffff quality=high wmode=opaque>";
			}
			?>');">[插入]</a><input type="hidden" name="localid[]" value="<?=$att['aid']?>">
						</td>
						<td>
						<?if($att['isimage']){?>
						<div style="border:1px solid #DADADA;width:250px;height:auto; position:absolute; text-align:center; background-color:#FFFFFF; display:none; padding:8px; margin-left:5px; z-index:99;" id="<?=$att['aid']?>"><img src="<?=$siteurl?>attachments<?=$att['filepath']?>" width="200" height="200"  border="0"  /></div>
						<?}?>
					</td></tr>
				<? }?>
				</table>
						</td>
					</tr>
					<tr id='tr0'>
						<td height="20" id='td0'><div id="attachlist"></div>
<input type="file" name="uploadify" id="uploadify" />
<p><a href="javascript:$('#uploadify').uploadifyUpload();">上传</a> | <a href="javascript:$('#uploadify').uploadifyClearQueue();">清空</a></p></td>
					</tr>
				</tbody>
			</table>
		</td>
		</tr>
		
		<tr>
		<th>是否外链</th>
		<td><input name="d[islink]" id="islink" type="checkbox" value="1" onclick="changeurl();" <? if ($content['islink']){?>checked="checked"<? }?> /> <input name="d[url]" type="text" id="url" size="60" maxlength="255"<? if ($content['islink']){?> value="<?=$content['url']?>"<? } else {?> disabled<? }?> /><div id="urltips" class="tips">请填写链接地址</div></td>
		</tr>
		
		<tr id="thumb">
		<th>展示图</th>
		<td><? if ($content[showimg]){?><img src="<?=$site?>attachments<?=$content[showimg]?>" /><br /><? }?><input name="showimg" type="file" id="showimg" size="40" /><div id="showimgtips" class="tips">展示图，请注意各分类下展示图大小不一样.</div></td>
		</tr>

		<tr>
		<th>状态</th>
		<td><input name="d[status]" type="radio" value="1" id="status1" <? if ($content['status'] == 1){?>checked="checked"<? }?> /><label for="status1">直接发布</label> <!--<input name="d[status]" type="radio" value="2" id="status2" <? if ($content['status'] == 2){?>checked="checked"<? }?> /><label for="status2"><font color="red">发布并推荐</font></label>--> <input name="d[status]" type="radio" value="0" id="status3" <? if ($content['status'] == 0){?>checked="checked"<? }?>/><label for="status3">存为草稿</label> <!--权重：<input name="d[weighing]" type="text" id="weighing" size="2" maxlength="2" <? if ($content['status'] > 2){?>value="<?=$content['status']?>"<? }?> /><div id="weighingtips" class="tips">可填3-99,数值越大，排名越靠前。</div>--></td>
		</tr>
		
		<tr>
		<th>&nbsp;</th>
		<td>
		<button value="true" type="submit" name="dosubmit" class="submit">提交保存</button></td>
		</tr>
	</table>
	</form>